<?php
 class rewrite
 {
     public static $rule=array( '{page}'=>'(\d+)', '{chapterid}'=>'(\d+)', '{novelkey}'=>'([a-zA-Z0-9_\-]+)', '{sitekey}'=>'([a-zA-Z0-9_\-]+)', '{novelid}'=>'(\d+)', '{author}'=>'([^\?]+?)', '{authorid}'=>'(\d+)', '{authorpinyin}'=>'([\w\-]+)', );
     public static function format($zym_14)
     {
         foreach ($zym_14 as &$zym_15) {
             $zym_15='/'.ltrim($zym_15, '/');
         }
         return $zym_14;
     }
     public static function createrouter($zym_14)
     {
         $zym_13=array();
         foreach ($zym_14 as $zym_11=>$zym_15) {
             $zym_15=ltrim($zym_15, '/');
             if ($zym_15!='') {
                 $zym_12=self::parserule($zym_15);
                 foreach ($zym_12 as $rule) {
                     preg_match_all('/\{([a-z]+)\}/', $rule, $zym_8);
                     foreach ($zym_8['0'] as $zym_5) {
                         $zym_6=empty(self::$rule[$zym_5])?'([a-zA-Z0-9]+)':self::$rule[$zym_5];
                         $rule=str_replace($zym_5, $zym_6, $rule);
                     }
                     $rule=rtrim($rule, '/');
                     $zym_13["^{$rule}(\?(.*))*$"]=str_replace('.', '/', $zym_11).'?'.implode('&', $zym_8[1]);
                 }
             }
         }
         return $zym_13;
     }
     public static function parserule($rule)
     {
         preg_match_all('#\[[^\[\]]*?\{\w+\}[^\[\]]*?\]#', $rule, $zym_8);
         $zym_12=array($rule);
         if ($zym_8['0']) {
             if (count($zym_8['0'])==1) {
                 $zym_12[]=str_replace($zym_8['0']['0'], '', $rule);
             } elseif (count($zym_8['0']==2)) {
                 $zym_12[]=str_replace($zym_8['0']['0'], '', $rule);
                 $zym_12[]=str_replace($zym_8['0']['1'], '', $rule);
                 $zym_12[]=str_replace(array($zym_8['0']['0'],$zym_8['0']['1']), '', $rule);
             } elseif (count($zym_8['0']==3)) {
                 $zym_12[]=str_replace($zym_8['0']['0'], '', $rule);
                 $zym_12[]=str_replace($zym_8['0']['1'], '', $rule);
                 $zym_12[]=str_replace($zym_8['0']['2'], '', $rule);
                 $zym_12[]=str_replace(array($zym_8['0']['0'],$zym_8['0']['1']), '', $rule);
                 $zym_12[]=str_replace(array($zym_8['0']['0'],$zym_8['0']['2']), '', $rule);
                 $zym_12[]=str_replace(array($zym_8['0']['1'],$zym_8['0']['2']), '', $rule);
                 $zym_12[]=str_replace(array($zym_8['0']['0'],$zym_8['0']['1'],$zym_8['0']['2']), '', $rule);
             }
             foreach ($zym_12 as &$zym_15) {
                 $zym_15=str_replace(array('[',']'), '', $zym_15);
             }
         }
         return $zym_12;
     }
     public static function iisrule($zym_14)
     {
         $zym_13= "[ISAPI_Rewrite]\r\n\r\nCacheClockRate 3600\r\nRepeatLimit 32\r\n";
         foreach ($zym_14 as $zym_11=>$zym_15) {
             $zym_15=ltrim($zym_15, '/');
             if ($zym_15!='') {
                 $zym_14=array();
                 preg_match_all('/\{([a-z]+)\}/', $zym_15, $zym_8);
                 $zym_10=1;
                 foreach ($zym_8['0'] as $zym_9=>$zym_7) {
                     $zym_6=empty(self::$rule[$zym_7])?'([a-zA-Z0-9]+)':self::$rule[$zym_7];
                     $zym_15=str_replace($zym_7, $zym_6, $zym_15);
                     ++$zym_10;
                     $zym_14[]="{$zym_8['1'][$zym_9]}=$".$zym_10;
                 }
                 $zym_13.="RewriteRule ^(.*)/{$zym_15}(\?(.*))*$ $1/index.php\?s=".str_replace(array('.','_'), '/', $zym_11).'&'.implode('&', $zym_14).'&$'.($zym_10+2)." [I]\r\n";
             }
         }
         return trim($zym_13);
     }
 }
